<template>
  <view class="box">
    <u-count-to :start-val="0" :end-val="number" :duration="1000"></u-count-to>

    <u-form ref="form1" class="form_ff" label-width="70">
      <u-form-item :label="item.name" v-for="item in list" style="width: 48%;">
        <!-- <u-input v-model="item.value" type="number" :border="true" maxlength="2" :placeholder="item.name"/> -->
        <u-number-box :min="1" :max="60" v-model="item.value" v-if="item.name != '武器'"></u-number-box>
        <u-number-box :min="1" :max="40" v-model="item.value" v-else></u-number-box>
      </u-form-item>
    </u-form>
    <u-button type="primary" text="神 50" @click="onchangeClick"></u-button>
    <u-cell-group>
      <u-cell icon="integral-fill" title="元素 774(400+150+150+74)" value="" :isLink="true"></u-cell>
      <u-cell icon="integral-fill" title="剑影 588(400+150+38)" value="" :isLink="true"></u-cell>
      <u-cell icon="integral-fill" title="战法 571(400+150+21)" value="再来一件神 53" :isLink="true"></u-cell>
      <u-cell icon="integral-fill" title="剑魂 503(400+103)" value="" :isLink="true"></u-cell>
      <u-cell icon="integral-fill" title="奶妈 348(150+150+48)" value="" :isLink="true"></u-cell>
    </u-cell-group>
    <image class="banner" src="@/static/xianshi.jpg" mode="widthFix" @click="back('/static/xianshi.jpg')"></image>
    <image class="banner" src="@/static/qwe.jpg" mode="widthFix" @click="back('/static/qwe.jpg')"></image>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        obj: [{
            level: 1,
            value: 2808769
          },
          {
            level: 2,
            value: 3089646
          },
          {
            level: 3,
            value: 3370523
          },
          {
            level: 4,
            value: 3651400
          },
          {
            level: 5,
            value: 3932277
          },
          {
            level: 6,
            value: 4213154
          },
          {
            level: 7,
            value: 4494031
          },
          {
            level: 8,
            value: 4774908
          },
          {
            level: 9,
            value: 5055785
          },
          {
            level: 10,
            value: 5336662
          },
          {
            level: 11,
            value: 5898416
          },
          {
            level: 12,
            value: 6460170
          },
          {
            level: 13,
            value: 7021924
          },
          {
            level: 14,
            value: 7583678
          },
          {
            level: 15,
            value: 8145432
          },
          {
            level: 16,
            value: 8707186
          },
          {
            level: 17,
            value: 9268940
          },
          {
            level: 18,
            value: 9830694
          },
          {
            level: 19,
            value: 10392448
          },
          {
            level: 20,
            value: 10954202
          },
          {
            level: 21,
            value: 11796833
          },
          {
            level: 22,
            value: 12639464
          },
          {
            level: 23,
            value: 13482095
          },
          {
            level: 24,
            value: 14324726
          },
          {
            level: 25,
            value: 15167357
          },
          {
            level: 26,
            value: 16571742
          },
          {
            level: 27,
            value: 17976127
          },
          {
            level: 28,
            value: 19380512
          },
          {
            level: 29,
            value: 20784897
          },
          {
            level: 30,
            value: 22189282
          },
          {
            level: 31,
            value: 24155420
          },
          {
            level: 32,
            value: 26121558
          },
          {
            level: 33,
            value: 28087696
          },
          {
            level: 34,
            value: 30053834
          },
          {
            level: 35,
            value: 32019972
          },
          {
            level: 36,
            value: 34828741
          },
          {
            level: 37,
            value: 37637510
          },
          {
            level: 38,
            value: 40446279
          },
          {
            level: 39,
            value: 43255048
          },
          {
            level: 40,
            value: 46063817
          },
          {
            level: 41,
            value: 50276971
          },
          {
            level: 42,
            value: 54490125
          },
          {
            level: 43,
            value: 58703279
          },
          {
            level: 44,
            value: 62916433
          },
          {
            level: 45,
            value: 67129587
          },
          {
            level: 46,
            value: 72747125
          },
          {
            level: 47,
            value: 78364663
          },
          {
            level: 48,
            value: 83982201
          },
          {
            level: 49,
            value: 89599739
          },
          {
            level: 50,
            value: 95217277
          },
          {
            level: 51,
            value: 103081831
          },
          {
            level: 52,
            value: 110946385
          },
          {
            level: 53,
            value: 118810939
          },
          {
            level: 54,
            value: 126675493
          },
          {
            level: 55,
            value: 134540047
          },
          {
            level: 56,
            value: 146336877
          },
          {
            level: 57,
            value: 158133707
          },
          {
            level: 58,
            value: 169930537
          },
          {
            level: 59,
            value: 181727367
          },
          {
            level: 60,
            value: 193524197
          }
        ],
        value: '',
        list: [{
          name: '武器',
          value: 40
        }, {
          name: '头肩',
          value: 40
        }, {
          name: '上衣',
          value: 40
        }, {
          name: '腰带',
          value: 40
        }, {
          name: '下装',
          value: 40
        }, {
          name: '鞋子',
          value: 40
        }, {
          name: '手镯',
          value: 40
        }, {
          name: '项链',
          value: 40
        }, {
          name: '戒指',
          value: 40
        }, {
          name: '辅助装备',
          value: 40
        }, {
          name: '魔法石',
          value: 40
        }, {
          name: '耳环',
          value: 40
        }]
      }
    },
    onLoad() {
      this.$uniCloud('addlog', {
        type: 'add',
        name: uni.getStorageSync('userInfo').nickName || '其他未登录用户',
        type_user: 'visit_dnf'
      })
    },
    computed: {
      number() {
        const initialNum = 0;
        const listData = this.list || [];
        const objData = this.obj || [];

        const total = listData.reduce((acc, item) => {
          const matchingElements = objData.filter(element => item.value === element.level);
          const sumValues = matchingElements.reduce((sum, element) => sum + element.value, 0);
          return acc + sumValues;
        }, initialNum);

        return total / 2174829.984;
      }
    },
    methods: {
      back(url) {
        uni.previewImage({
          urls: [url]
        })
      },
      onchangeClick() {
        this.list.forEach(item => {
          item.value = 50
        })
      }
    }
  }
</script>

<style lang="less">
  .box {
    background-color: #FFF;
    padding: 20rpx;
  }

  .form_ff {
    display: flex;
    flex-wrap: wrap;
    gap: 10rpx;
  }

  .banner {
    width: 100%;
  }
</style>